var namePlugins = {

    html: function (nameArray,name,zhibiaoArray,zhibiaoCaptionArray,requestTypeArray,panelNames) {
        if(nameArray==null||nameArray.length<=0){
            return "";
        }
        var html="<div class=\"pluginsDiv\" id='namePluginsDiv'>";

        //原代码
        //var nameSelectHtml="<div class=\"pluginsSingleRows layui-form-item \"><label class='layui-form-label'>指标类型:</label><div class='layui-input-block'><select lay-filter='nameSelect' id='nameSelect'>";
        //新增自定义
        var zhibiaoName="指标类型:";
        if(panelNames.hasOwnProperty("zhibiaoName")){
            zhibiaoName=panelNames.zhibiaoName+":";
        }
        var nameSelectHtml="<div class=\"pluginsSingleRows layui-form-item \"><label class='layui-form-label'>"+zhibiaoName+"</label><div class='layui-input-block'><select lay-filter='nameSelect' id='nameSelect'>";
        //自定义结束

        var nameSelectHtml="<div class=\"pluginsSingleRows layui-form-item \"><label class='layui-form-label'>指标类型:</label><div class='layui-input-block'><select lay-filter='nameSelect' id='nameSelect'>";
        var zhibiaoSelectHtml="";
        var fenxiSelectHtml="";
        for(var i=0;i<nameArray.length;i++){
            nameSelectHtml+="<option data-val='"+ nameArray[i].requestFlag +"' value='"+nameArray[i].name+"' ";
            if(name==nameArray[i].name){
                nameSelectHtml+="selected=\"selected\"";
            }
            nameSelectHtml+=" >"+nameArray[i].name+"</option>";
        }
        nameSelectHtml+="</select></div></div>";
        if(zhibiaoArray!=null&&typeof(zhibiaoArray)!='underfined'&&zhibiaoArray.length>0){
            zhibiaoSelectHtml="<div class=\"pluginsSingleRows layui-form-item \"><label class='layui-form-label'>分析类别:</label><div class='layui-input-block'><select id='zhibiaoSelect'>";
        }else{
            zhibiaoSelectHtml="<div class=\"pluginsSingleRows layui-form-item \" style=\"display:none;\"><label class='layui-form-label'>分析类别:</label><div class='layui-input-block'><select id='zhibiaoSelect'>";
        }
        for(var i=0;i<zhibiaoArray.length;i++){
            zhibiaoSelectHtml+="<option value='"+zhibiaoArray[i]+"' ";
            if(i==0){
                zhibiaoSelectHtml+="selected=\"selected\"";
            }
            zhibiaoSelectHtml+=" >"+zhibiaoCaptionArray[i]+"</option>";
        }
        zhibiaoSelectHtml+="</select></div></div>";
        fenxiSelectHtml="<div class=\"pluginsSingleRows layui-form-item \" style='display:none;'><label class='layui-form-label'>查询类型:</label><div class='layui-input-block'><select lay-filter='selectTypeSelect' id='selectTypeSelect'>";

        //  循环留着备用
        for(var i=0;i<requestTypeArray.length;i++){
            var cnName=getCnName(requestTypeArray[i]);
            if(cnName!=""){
                fenxiSelectHtml+="<option value='"+requestTypeArray[i]+"' ";
                if(i==0){
                    fenxiSelectHtml+="selected=\"selected\"";
                }
                fenxiSelectHtml+=" >"+cnName+"</option>";
            }
        }

        function getCnName(name){
            if(name=="Spatial"){
                return "实时数据分析";
            }else if(name=="History"){
                return "历史数据分析";
            }else if(name=="Forecast"){
                return "预报数据分析";
            }else{
                return "";
            }
        }


//    fenxiSelectHtml+="<option value=\"Spatial\">实时数据分析</option>";
//    fenxiSelectHtml+="<option value=\"History\">历史数据查询</option>";
        fenxiSelectHtml+="</select></div></div>";
        html+=nameSelectHtml+fenxiSelectHtml+zhibiaoSelectHtml;

        html+="</div>";
        return html;
    },
    getData: function () {
        var nameVal=$('#nameSelect option:selected') .val();
        var timeVal= $('#timeTypeSelect option:selected') .val();
        if(nameVal=="平均气温" && timeVal=="HourTimeType"){
            Global.postData.requestFlag = "Yaosu_Temp_HourAvgTemp_Spatial";
        }else if(nameVal=="累计降水" && timeVal=="HourTimeType"){
            Global.postData.requestFlag = "Yaosu_Rain_HourSum_Spatial";
        }
        else{
            Global.postData.requestFlag = getRequestFlag(Global.currElementObj.isGroupByDay);
        }

        //by lushangnan 20181129
        Global.postData.yaosuQueryRequestAnalysisType=$("#selectTypeSelect").val();
//    if(Global.postData.yaosuQueryRequestAnalysisType=="History"){
//        Global.postData.historyCalWays = [Global.postData.calWay];
//      }
        //by end


    },
    renderCallback: function () {

        /*指标类型切换，加载xml配置*/
        layForm.on('select(nameSelect)', function (data) {

            /*切换指标类型，加载对应的业务面板*/
            initControlByName(data.value);

        });


        /*查询类型切换，处理历史时间*/
        layForm.on('select(selectTypeSelect)', function (data) {
            queryTypeChange(data.value);
        });

        function queryTypeChange(value) {
            var Spatial = $('#dateTimeDiv');
            var History = $('#PeriodYearDiv');
            var thresholdRange=$('#thresholdRangeDiv');//范围
            var historyPlugins=$('#historyPluginsDiv');//历史统计
            if ( value === 'Spatial') {
                Spatial.show();
                History.hide();
            } else if ( value === 'History' ) {
                History.show();
                Spatial.hide();
            }else if(value === 'Forecast'){
                Spatial.show();
                History.hide();
                thresholdRange.hide();
                historyPlugins.hide();
            }
        }

        queryTypeChange($('#selectTypeSelect').val());

    }


};

function getRequestFlag(isGroupByDay){
    var nameSelect=$("#nameSelect").children('option[value="'+ $("#nameSelect").val() +'"]').attr('data-val');
    var zhibiaoSelect=$("#zhibiaoSelect").val();
    var timeselectval=$('#timeTypeSelect option:selected').val();
    if(zhibiaoSelect!=null&&zhibiaoSelect!=""&&typeof(zhibiaoSelect)!="underfined"){
        zhibiaoSelect="_"+zhibiaoSelect;
    }else{
        zhibiaoSelect="";
    }
    if(isGroupByDay=="true"||isGroupByDay==true){//单日查询
        if(typeof($("#calTypeStaticSelect").val())!="undefined"&&$("#calTypeStaticSelect").val()!="NoneCalWay"){//单日计算类型选中
            if($("#selectTypeSelect").val()=="History"){
                return nameSelect+zhibiaoSelect+"_HistorySamePeriod";
            }else{
                return nameSelect+zhibiaoSelect+"_Spatial";
            }
        }else{
            if($("#selectTypeSelect").val()=="History"){
                return nameSelect+zhibiaoSelect+"_History";
            }else if($("#selectTypeSelect").val()=="Spatial"){
                return nameSelect+zhibiaoSelect+"_Spatial";
            }
            else{
                return nameSelect+zhibiaoSelect+"_History";
            }
        }
    }else{//待完善
        if($("#selectTypeSelect").val()=="History"){
            return nameSelect+zhibiaoSelect+"_HistorySamePeriod";
        }else if(timeselectval=='DayTimeType' || timeselectval=='HourTimeType'){
            return nameSelect+zhibiaoSelect+"_Spatial";
        }else{
            return nameSelect+zhibiaoSelect+"_History";
        }

    }
}


